package dnl.util.ui.image;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class AAA {

	public static void main(String[] args) throws IOException {
		JFrame f = new JFrame();
		 f.setSize(600, 800);
		 BufferedImage i = ImageIO.read(new File("X:\\STF\\pics\\forest floor.JPG"));
		 final ImageCropper c = new ImageCropper(i);
		 c.addChangeListener(new ChangeListener() {      
		@Override
		  public void stateChanged(ChangeEvent e) {
		   System.out.println(c.getCroppedImage().getWidth() + " * " + c.getCroppedImage().getHeight());
		  }      
		 });
		 f.add(c);
		 JButton jb = new JButton("Crop");
		 jb.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				JLabel jl = new JLabel(new ImageIcon(c.getCroppedImage()));
				JOptionPane.showMessageDialog(null, jl);
			}
		 });
		 f.add(jb, BorderLayout.SOUTH);
		 f.setVisible(true);
		 
		//You can even use a BufferedImageOp (= a filter on an image) to filter the part of the image which is outside the cropped part :

		//BufferedImageOp filter = new CompoundFilter(new BoxBlurFilter(3, 3, 3), new GrayscaleFilter());

	}
}
